import { mapState, mapMutations } from 'vuex';
export default {
    computed: {
    	...mapState(['globalConfig', 'userInfo'])
    },
    methods: {
        ...mapMutations(['afterRz', 'afterGetUserProfiole']),
        startFaceValidate: function (item) {
            var vm = this;
			if (vm.$Util.idCardValidator(vm.userInfo.credentialsNo)) {
				uni.$u.toast('很抱歉，您的证件类型暂不支持实名认证');
				return;
			}
			uni.showLoading();
            vm.doWxLogin().then(res => {
				var openId = res.openId;
				if (!vm.userInfo.userName || vm.userInfo.credentialsNo) {
					uni.showModal({
						title: '提示',
						content: '您的用户信息不完整，无法实名注册, 请尝试注销账号重新注册。',
						showCancel: false
					});
					return;
				}
                wx.startFacialRecognitionVerify({
                    name: vm.userInfo.userName,
                    idCardNumber: vm.userInfo.credentialsNo,
                    complete: function (res) {
						uni.hideLoading();
                        if (res.errCode == 0) {
                			uni.showLoading();
                            vm.getAndLoad('更新认证', `/mobile/h5/covid19/apiRyzc/editSave.jsp?openId=${openId}&faceValidate=是`, function (res) {
                                uni.hideLoading();
                            	if (res.code == 0) {
                                    uni.$u.toast('认证通过');
                                    vm.afterRz();
                                } else {
                                    uni.showModal({
                                        title: '提示',
                                        content: res.msg || '认证失败',
                                        showCancel: false
                                    });
                                }
                            });
                        }
                    }
                })
            });
        },
		getUserProfile: function () {
			let that = this
			uni.showLoading();
			that.doWxLogin().then(res => {
			    var openId = res.openId;
				uni.getUserProfile({
					desc: "用于完善用户信息",
					success: (res1) => {
						var userInfo = res1.userInfo;
						that.getAndLoad('更新个人信息', '/mobile/teacher/api/v1/user/updateAvatar.jsp?' + that.$Util.stringify({
							openId: openId,
							avatar: userInfo.avatarUrl,
							nickname: userInfo.nickName,
                            // ...that.userInfo
						}), function (res) {
						    uni.hideLoading();
							if (res.code == 0) {
						       that.afterGetUserProfiole(res1.userInfo);
							   that.avatarGot = true;
						    } else {
						        uni.showModal({
						            title: '提示',
						            content: res.msg || '保存失败',
						            showCancel: false
						        });
						    }
						});
						
					},
					fail: (err) => {
						uni.hideLoading();
						uni.showToast({
							icon:"none",
							title:'您拒绝了'
						})
					}  
				})
			});
		}
    },
}